package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstant;
import com.heima.model.article.dto.ArticleDto;
import com.heima.model.article.dto.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {

    @Resource
    private ApArticleService apArticleService;

    /**
     * 发布 修改文章  保存草稿
     */
    @PostMapping("/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    /**
     * 用户端首页加载
     */
    @PostMapping("load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto, ArticleConstant.LOAD_MORE);
    }


    /**
     * 加载更多
     *
     * @param dto
     * @return
     */
    @PostMapping(path = "/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto, ArticleConstant.LOAD_MORE);
    }

    /**
     * 加载最新
     *
     * @param dto
     * @return
     */
    @PostMapping(path = "/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(dto, ArticleConstant.LOAD_NEW);
    }

}
